package com.fyt.controller;

import com.alibaba.fastjson.JSONObject;
import com.fyt.service.buildService;
import com.fyt.utils.ExecuteCodeResponse;
import org.joor.Reflect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;
import java.util.UUID;

@RestController
public class buildController {
    @Autowired
    private buildService buildService;

    @RequestMapping("/build/java/")
    @ResponseBody
    public JSONObject ExecuteJava(@RequestParam Map<String,String> map){
        String code = map.get("code");
        String input = map.get("inputCode");
        ExecuteCodeResponse build = buildService.ExecuteJAVA(code,input);
        JSONObject res = new JSONObject();
        res.put("message",build.getMessage());
        res.put("outputList",build.getOutputList());
        res.put("statusCode",build.getStatus());
        res.put("judgeInfo",build.getJudgeInfo());
        return res;
    }

    @RequestMapping("/build/cpp/")
    @ResponseBody
    public JSONObject ExecuteCPP(@RequestParam Map<String,String> map){
        String code = map.get("code");
        String input = map.get("inputCode");
        ExecuteCodeResponse build = buildService.ExecuteCPP(code,input);
        JSONObject res = new JSONObject();
        res.put("message",build.getMessage());
        res.put("outputList",build.getOutputList());
        res.put("statusCode",build.getStatus());
        res.put("judgeInfo",build.getJudgeInfo());
        return res;
    }

}
